import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

part 'my_event.dart';
part 'my_state.dart';

class MyBloc extends Bloc<MyEvent, MyState> {
  MyBloc() : super(MyInitial()) {
    on<MyUpdateCount>(_myUpdateCount);
  }

  Future<void> _myUpdateCount(
      MyUpdateCount event, Emitter<MyState> emit) async {
    if (event.type == 'add') {
      emit(CountUpdate(count: state.count + event.init));
    } else {
      emit(CountUpdate(count: state.count - event.init));
    }
  }
}
